package com.example.toutiao.ui.main.act

import androidx.recyclerview.widget.LinearLayoutManager
import com.example.toutiao.R
import com.example.toutiao.base.BaseActivity
import com.example.toutiao.ui.main.adpater.SearchAdapter
import com.example.toutiao.ui.main.model.RecMainModel
import com.example.toutiao.ui.main.presenter.SearchPresenter
import com.example.toutiao.ui.main.view.SearchView
import kotlinx.android.synthetic.main.activity_search.*

class SearchActivity : BaseActivity<SearchView, SearchPresenter>(), SearchView {
    override fun getLayoutId(): Int = R.layout.activity_search

    override fun initView() {
        rv_search_list.layoutManager = LinearLayoutManager(this)
        icon_back.setOnClickListener { finish() }
    }

    override fun initData() {
        getPresenter()!!.getSearchHis()
    }

    override fun createPresenter(): SearchPresenter = SearchPresenter()

    override fun isRegister(): Boolean = true

    override fun <T> setData(data: T) {
        if (data != null) {
            val model=data as RecMainModel
            rv_search_list.adapter=SearchAdapter(model)
            if(model.recommendList!=null&&model.recommendList.size>0){
                rec_title.hint="${model.recommendList[0].name}"
            }
        }
    }
    override fun setError(err: String) {

    }

}